package com.ustc.hewei.nettyrpc2_0.netty.client.handler;

import com.ustc.hewei.nettyrpc2_0.common.codec.CommonDecode;
import com.ustc.hewei.nettyrpc2_0.common.codec.CommonEncode;
import io.netty.channel.ChannelHandlerContext;
import io.netty.channel.ChannelInitializer;
import io.netty.channel.ChannelPipeline;
import io.netty.channel.socket.SocketChannel;
import io.netty.handler.timeout.IdleStateHandler;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.stereotype.Component;

import java.util.ResourceBundle;
import java.util.concurrent.TimeUnit;

/**
* @description: 客户端初始化handler
* @author hewei
* @date 2022/9/7 21:45
* @version 1.0
*/
public class ClientInitializerHandler extends ChannelInitializer<SocketChannel> {

    @Override
    protected void initChannel(SocketChannel socketChannel) throws Exception {
        ChannelPipeline pipeline = socketChannel.pipeline();
        pipeline.addLast(new IdleStateHandler(0, 5, 0, TimeUnit.SECONDS));
        pipeline.addLast(new CommonEncode());
        pipeline.addLast(new CommonDecode());
        pipeline.addLast(new ClientHandler());
    }
}
